<?php
use yii\helpers\Url;
use yii\web\View;
use app\assets\SolutionCreativeAsset;
SolutionCreativeAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  [
    'label' => \Yii::t('solution', 'Solution'),
    'url' => ['solution-list']
  ],
  \Yii::t('solution', 'Edit Solution')
];
$jsMsgs = $this->context->loadJsMsgs([
  'table',
  'dialog',
  'creative'
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('solution', 'Solution')?>
    <small><?=\Yii::t('solution', 'Edit Solution')?></small>
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-edit"></i>
    <?=\Yii::t('solution', 'Edit Solution')?>
    <ul class="list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
	<div class="panel-body">
    <div class="panel-heading">
      <h3 id="strategy_name"><?=$solution['name']?></h3>
    </div>
    <div class="step-container">
      <ul class="step-wrap">
        <li class="step-undone step-done">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Label')?>">
            <i class="fa fa-check"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Label')?></p>
        </li>
        <li class="step-undone step-done">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Campaign')?>">
            <i class="fa fa-check"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Campaign')?></p>
        </li>
         <li class="step-undone step-done">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Solution')?>">
            <i class="fa fa-check"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Solution')?></p>
        </li>
         <li class="step-undone step-active">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Creative')?>">
            <i class="fa fa-chevron-right"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Creative')?></p>
        </li>
      </ul>
      <div class="step-progress-bar">
        <div class="step-progress" style="width: 100%;"></div>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <div class="section-step">
          <ol class="list-inline main-flow">
            <li class="first">
              <a href="<?= Url::to(['solution/solution-basic-edit']);?>?solution_id=<?= $solution['id'] ?>" class="cancleFocus">
                <b>①</b>
                <?=\Yii::t('solution', 'Basic')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li>
              <a href="<?= Url::to(['solution/solution-resource-edit']);?>?solution_id=<?= $solution['id'] ?>" class="cancleFocus">
                <b>②</b>
                <?=\Yii::t('solution', 'Resource')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li>
              <a href="<?= Url::to(['solution/solution-target-edit']);?>?solution_id=<?= $solution['id'] ?>" class="cancleFocus">
                <b>③</b>
                <?=\Yii::t('solution', 'Condition')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li>
              <a href="<?= Url::to(['solution/solution-bidding-edit']);?>?solution_id=<?= $solution['id'] ?>" class="cancleFocus">
                <b>④</b>
                <?=\Yii::t('solution', 'Bidding')?>
                <span><i class="fa fa-arrow-right"></i></span>
              </a>
            </li>
            <li class="last current">
              <a href="<?= Url::to(['solution/solution-creative-edit']);?>?solution_id=<?= $solution['id'] ?>" class="cancleFocus">
                <b>⑤</b>
                <?=\Yii::t('solution', 'Creative')?>
              </a>
            </li>
          </ol>
        </div>
      </div>
    </div>
    <div class="panel panel-dotted">
      <div class="panel-heading">
        <div class="btn-group btn-group-sm pull-right" role="group" aria-label="...">
          <a href="javascript:void(0);" class="btn btn-info" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Loading')?>..." id="bind-creative-btn" title="<?=\Yii::t('solution', 'Bind Creative')?>">
            <i class="fa fa-link"></i>
            <?=\Yii::t('solution', 'Bind Creative')?>
          </a>
		  <?php
			$loading = \Yii::t('common', 'Loading').'...';
			$webAdd = \Yii::t('solution', 'Add Web Creative');
			$appAdd = \Yii::t('solution', 'Add APP Creative');
			$webCrt = \Yii::t('solution', 'New Web Creative');
			$appCrt = \Yii::t('solution', 'New APP Creative');
			$mobDiv = <<<FINE
          <!--a href="javascript:void(0);" class="btn btn-success" data-loading-text="<i class='fa fa-spinner fa-spin'></i> $loading" id="new-web-operate-btn" title="$webAdd">
            <i class="fa fa-plus-circle"></i>
            $webCrt
          </a -->
          <a href="javascript:void(0);" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin'></i> $loading" id="new-app-operate-btn" title="$appAdd">
            <i class="fa fa-plus-circle"></i>
            $appCrt
          </a>

FINE;
			if (in_array(3, $_SESSION['traffic_slot'])) echo $mobDiv;
?>
		  <?php
// 			$loading = \Yii::t('common', 'Loading').'...';
// 			$add = \Yii::t('solution', 'Add Mobile Video Creative');
// 			$mvCrt = \Yii::t('solution', 'New Mobile Video Creative');
// 			$mvDiv = <<<FINE
//           <a href="javascript:void(0);" class="btn btn-success" data-loading-text="<i class='fa fa-spinner fa-spin'></i> $loading" id="new-mobile-video-operate-btn" title="$add">
//             <i class="fa fa-plus-circle"></i>
//             $mvCrt
//           </a>
// FINE;
// 			if (in_array(4, $_SESSION['traffic_slot'])) echo $mvDiv;
?>
        </div>
      </div>
      <div class="panel-body pos-r">
        <div id="list-loading-wrap" class="local-loading-wrap"></div>
        <form class="form-horizontal" id="data-frm" method="POST" action="<?php echo Url::to(['solution/new-solution-creative-handle']);?>" role="form">
          <fieldset>
            <div class="table-responsive">       
              <input id="ckb-ids" type="hidden" name="creative_id" value="">
              <input type="hidden" name="target.creaitve_list" value="">
              <table class="table table-hover table-striped table-bordered table-condensed" id="data-table" data-tag="vm-adserver.solution-creative-edit-list">
                <thead>
                  <tr>
                    <th class="tab-sm" data-resizable-column-id="id" data-search="on" data-filter="on">
                      ID
                    </th>
                    <th data-resizable-column-id="name" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Creative Name')?></th>
                    <th data-resizable-column-id="status" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Status')?></th>
                    <!-- <th data-resizable-column-id="creativeType" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Type')?></th> -->
                    <th data-resizable-column-id="materialType" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Material Type')?></th>
                    <th data-resizable-column-id="creativeSize" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Size')?></th>
                    <th class="tab-lg" data-resizable-column-id="vocation" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Vocation')?></th> 
                    <th data-resizable-column-id="cost" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Cost')?></th>
                    <th data-resizable-column-id="showCount" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Shows')?></th>
                    <th data-resizable-column-id="clickCount" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Clicks')?></th>
                    <th data-resizable-column-id="clickRate" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Click Rate(%)')?></th>
                    <!-- <th data-resizable-column-id="cpm" data-search="on" data-filter="on">CPM(<i class="fa fa-rmb"></i>)</th> -->
                    <th data-resizable-column-id="cpc" data-search="on" data-filter="on">CPC(<i class="fa fa-rmb"></i>)</th>
                    <th class="tab-op" data-resizable-column-id="operate" data-filter="on"><?=\Yii::t('solution', 'Actions')?></th>
                  </tr>
                </thead>
                <tbody></tbody>
              </table>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <div class="btn-form-group pull-right">
                  <button type="submit" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Submit')?></button>
                  <a href="<?php echo Url::to(['solution/solution-list']); ?>" class="btn btn-default"><?=\Yii::t('common', 'Back')?></a>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>
<div class="modal bootstrap-dialog type-primary fade" id="bind-creative-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header bootstrap-dialog-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title bootstrap-dialog-title"><?=\Yii::t('solution', 'Bind Creative')?></h4>
      </div>
      <div class="modal-body">
        <form action="<?php echo Url::to(['bind-solution-creative-handle']);?>" method="post" class="form-horizontal" id="bind-creative-frm">
          <input class="hidden" type="text" name="solution_id" value="<?= $solution['id']?>">
          <fieldset>
            <table class="table table-hover table-striped table-bordered table-condensed" id="bind-creative-table">
              <thead>
                <tr>
                  <th data-resizable-column-id="id" data-search="on" data-filter="on">ID</th>
                  <th data-resizable-column-id="name" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Creative Name')?></th>
                  <th data-resizable-column-id="creativeType" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Type')?></th>
                  <th data-resizable-column-id="materialType" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Material Type')?></th>
                  <th data-resizable-column-id="creativeSize" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Size')?></th>
                  <th data-resizable-column-id="vocation" data-search="on" data-filter="on"><?=\Yii::t('solution', 'Vocation')?></th>
                  <th data-resizable-column-id="operate" data-filter="on">
                    <label>
                      <input type="checkbox" class="ckb-all"> <?=\Yii::t('solution', 'Actions')?>
                    </label>
                  </th>
                </tr>
              </thead>
              <tbody></tbody>
            </table>
          </fieldset>
          <fieldset>
            <div class="form-group mb">
              <div class="col-sm-offset-2 col-sm-10">
                <div class="btn-form-group pull-right">
                  <input class="operate-type" type="hidden" name="operate_type" value="save">
                  <button type="submit" class="btn btn-primary save-btn" data-operate="save" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Save')?></button>
                  <button type="button" class="btn btn-default" data-dismiss="modal"><?=\Yii::t('common', 'Close')?></button>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>
<?php
  // $url = yii::getAlias('@web').'/response/solution/solutionCreativeDataList.php';
  $url = Url::to(['get-solution-creatives', 'solution_id' => $solution['id']]);
  $bindCreativeUrl = Url::to(['creative/get-solution-unbind-creative', 'solution_id' => $solution['id']]);
  $creativeWebIfrUrl = Url::to(['add-web-solution-creative', 'solution_id' => $solution['id']]);
  $creativeAppIfrUrl = Url::to(['add-app-solution-creative', 'solution_id' => $solution['id']]);
  $creativeOverlayIfrUrl = Url::to(['add-overlay-solution-creative', 'solution_id' => $solution['id']]);
  $creativeMobileVideoIfrUrl = Url::to(['add-mobile-video-solution-creative', 'solution_id' => $solution['id']]);
  $listUnlinkOpUrl = Url::to(['unbind-solution-creative', 'solution_id' => $solution['id']]);
  $listPreviewOpUrl = Url::to(['mobile-creative-preview']);
  $listMobileVideoPreviewOpUrl = Url::to(['creative/list-mobile-video-creative-preview']);
  $filter = '';    // 需要屏蔽数据时 $dataFilter = ''， 显示数据 $dataFilter = true
  $this->registerJs("VAM.setVar('FILTER_STATUS','$filter');",View::POS_HEAD);
  $this->registerJs("VAM.setVar('CREATIVE_DATA_LIST', '$url')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('CREAITVE_WEB_IFR_URL','$creativeWebIfrUrl')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('CREAITVE_APP_IFR_URL','$creativeAppIfrUrl')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('CREAITVE_MOBILE_VIDEO_IFR_URL','$creativeMobileVideoIfrUrl')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('LIST_PREVIEW_MOBILE_VIDEO_OP_URL','$listMobileVideoPreviewOpUrl')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('LIST_UNLINK_OP_URL', '$listUnlinkOpUrl')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('BIND_CREAITVE_URL','$bindCreativeUrl')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('LIST_PREVIEW_OP_URL','$listPreviewOpUrl')", View::POS_HEAD);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/solution/newSolutionCreative.js"]);
  });
</script>
